<?php
/**
 * Created by PhpStorm.
 * User: sks
 * Date: 2015/12/15
 * Time: 13:49
 */

class Involved_RefundPlanModel extends BaseModel{

    protected $table = 'refund_plan';

    /**
     * 回款计划
     * @return mixed
     */
    public function RefundPlan($user_id)
    {
        return  DB::table($this->table)
            ->select('item.status as item_status','deadline','refund_plan.auto_id','refund_plan.user_id','refund_plan.item_id','refund_plan.item_number','refund_plan.amount_capital','refund_plan.amount_accrual','refund_plan.stage','refund_plan.start_time','refund_plan.refund_time','refund_plan.status')
            ->leftJoin('item','item.auto_id','=','refund_plan.item_id')
            ->where('item.status','REPAYING')
            ->where('user_id',$user_id)
            ->get();
    }

    /**
     * 总回款金额
     * @return mixed
     */
    public function RefundPlanAll()
    {
        return  DB::table($this->table)
            ->leftJoin('item','item.auto_id','=','refund_plan.item_id')
            ->where('item.status','REPAYING')
            ->sum('refund_plan.amount_accrual');
    }


}